<div class="row">
<?php echo CHtml::activeLabelEx($models['company'],'cname'); ?>
<?php echo CHtml::activeTextField($models['company'], 'cname',array('size'=>40));?>
</div>
<div class="row">
	<?php echo CHtml::activeLabelEx($address,"[$belong]address"); ?>
	<?php echo CHtml::activeTextField($address, "[$belong]type", array('watermark'=>'Labeling the address')); ?>
	<?php echo CHtml::activeTextField($address,"[$belong]postal",array('maxlength'=>20,'watermark'=>'Address postal code')); ?>
</div>
<div>
	<?php echo CHtml::activeTextArea($address,"[$belong]address",array('rows'=>3, 'cols'=>42)); ?>
</div>
<div id="contacts">
<div class="row">
	<?php echo CHtml::label("Tel No.", 'telephone');?> <?php foreach($address->contacts as $i=>$item): if($item['type']<10): ?>
	<?php echo CHtml::activeDropDownList($item, "[$belong]type", company_contacts::model()->teleType,array('name'=>"company_contacts[$belong][$i][type]")); ?>
	<?php echo CHtml::activeTextField($item,"[$belong]ref",array('size'=>25,'maxlength'=>35,'name'=>"company_contacts[$belong][$i][ref]")); ?>
	<?php endif;  endforeach; ?>
</div>
<div class="row">
	<?php echo CHtml::label("Fax No.", 'fax');?> <?php foreach($address->contacts as $i=>$item): if($item['type']>9 && $item['type']<20): ?>
	<?php echo CHtml::activeDropDownList($item, "[$belong]type[$i]", company_contacts::model()->faxType,array('name'=>"company_contacts[$belong][$i][type]")); ?>
	<?php echo CHtml::activeTextField($item,"[$belong]ref[$i]",array('size'=>25,'maxlength'=>35,'name'=>"company_contacts[$belong][$i][ref]")); ?>
	<?php endif; endforeach; ?>
</div>
<div class="row">
	<?php echo CHtml::label("Email", 'email');?> <?php foreach($address->email as $i=>$item): ?>
	<?php echo CHtml::activeDropDownList($item, "[$belong]type[$i]", company_email::model()->emailType,array('name'=>"company_email[$belong][$i][type]")); ?>
	<?php echo CHtml::activeTextField($item,"[$belong]ref[$i]",array('size'=>25,'maxlength'=>35,'name'=>"company_email[$belong][$i][ref]")); ?>
	<?php endforeach; ?>
</div>
</div>

<?php
$cs = Yii::app()->getClientScript();
$contact = count($address->contacts)-1;
$email = count($address->email)-1;
$s =<<<EOD
        $('div#tabaddress').data('index',$belong);
        $('div#contacts').eq($belong).data('index',$contact);
        $('div#email').eq($belong).data('index',$email);
EOD;
$cs->registerScript('registerIndex#'.$belong,$s);
?>